home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7105 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  46 lines

  1. Path: news1.sunbelt.net!dial-13
  2. From: dking@SunBelt.Net
  3. Newsgroups: comp.lang.c
  4. Subject: accessing structures (newbie question)
  5. Date: 19 Feb 1996 00:34:20 GMT
  6. Organization: SunBelt.Net INTERNET Access
  7. Message-ID: <4g8gic$o6u@news1.sunbelt.net>
  8. NNTP-Posting-Host: dial-13.r1.gaagst.sunbelt.net
  9. X-Newsreader: News Xpress Version 1.0 Beta #4
  10.  
  11. Ok. having trouble accessing structure. here I define a pointer and malloc the 
  12. memory:
  13.  
  14. struct picture *photos;
  15. photos = (struct picture *)malloc(1000 * sizeof(picture));
  16.  
  17. now I try to store data into structures...
  18.  
  19.     for (x=0;x<num_of_files;x++)
  20.     {
  21.         strncpy(photos->filename, filelist[x],12);
  22.         strncpy(photos->diskname, inputdisk,12);
  23.         strncpy(photos->indexname, inputindex,12);
  24.     }
  25.  
  26. now I try to read data...
  27.  
  28.  
  29. for (x=0;x<num_of_files;x++)
  30. {
  31.    
  32. printf("%sdisk%sindex%s\n",photos->filename,photos->diskname,photos->indexname
  33. ;    }
  34.  
  35. Obviously I'm pointing to the first of the 1000 structures the entire time. 
  36. Now for the 60,000 dollar question: HOW do I access the rest of the 
  37. structures? My tutuorial doesnt have any examples of accessing  MALLOCed 
  38. structures. The one example on structures defines it as an array (struct 
  39. picture *photos[x] ) but 1000 elements is too large an array and the example 
  40. with malloc uses floating point data accessed by using (photos[x]) which 
  41. doesnt work either with the strnccpy or with the -> operator.
  42.  
  43. I'd Appreciate any assistance you might offer.
  44.  
  45.                 Daryl
  46.